#include <signal.h>
#include <stdio.h>
#include <stdlib.h>

void sig_handler(int signo)
{
    printf("\r\nSIGINT signal!\r\n");
    exit(0);
}

int main(int argc, char *argv[])
{
  
   signal(SIGINT, sig_handler);
    while (1)
    {
        printf("Waiting for signal...\r\n");
        sleep(2);
    }
    //按下Ctrl+C 退出程序 不会执行下面的printf
    printf("End of program!\r\n");
    return 0;
}